<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,app.stock.common.*,app.stock.web.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=Stock.label%></title>
<%@ include file="head.jsp"%>
<%@ include file="js.jsp"%>
<script type="text/javascript">
    window.onload = function(){
        var oButtons = $('input');
        for(var i = 0; i < oButtons.length; i++){
            (function(){
                    if(this.type == 'submit'){
                        this.onclick = function(){
                            document.forms[0].action = 'StockCtrl?action=query&page=summary.jsp';
                            document.forms[0].submit();
                        };
                    }
                }
            ).call(oButtons[i]);            
        }
        var showHasAmountValue = getCookie('showHasAmount');
        if(showHasAmountValue ==='false'){
        	document.getElementById('showHasAmountId').checked = false;
        }else{
        	document.getElementById('showHasAmountId').checked = true;
        }        
        showHasAmount();
    };
    function showHasAmount(){
        var trs = $("tr[name='tx_record']");
        var tds = $("td[name='<%=Stock.currentAmountName%>']");
        if(document.getElementById('showHasAmountId').checked){
            for(i=0;i<trs.length;i++){
                if(parseInt(tds[i].innerHTML)==0){
                    trs[i].style.display='none';                                
                }
            }
            document.cookie = 'showHasAmount=' + true; 
        }
        else{
            for(i=0;i<trs.length;i++){
                if(parseInt(tds[i].innerHTML)==0){
                    trs[i].style.display='';                                
                }
            }
            document.cookie = 'showHasAmount=' + false;
        }
    };
</script>
</head>

<body>
<%@ include file="bodyhead.jsp"%>
<div align="center">
	<form method="post" name="query_form" action="StockCtrl?action=query&page=summary.jsp&target=summary.jsp">
	<table>
		<tr>
			<td><label><%=Transaction.codeLabel%></label></td>
			<td><input name="<%=Transaction.codeName%>"></input></td>
			<td><input type="submit" value="<%=Constants.label_operationQuery%>"></input></td>
			<td></td>
			<td><input id="showHasAmountId" type="checkbox" onchange="showHasAmount();">只显示持股</input></td>
		</tr>
	</table>
	</form>
	<form name="recalc_form" method="post" action=""
		onsubmit="submitForm('recalc_form',['page=summary.jsp','action=update'])">
		<%@ include file="summary_table.jsp"%>
		<input name="submit" type="submit" value="<%=Constants.label_operationRecalc%>">
	</form>
</div>
<div align="center">
	<%
		Account acct = (Account) request.getAttribute(WebConstants.key_attr_acct);
		request.removeAttribute(WebConstants.key_attr_acct);
		if (acct != null) {
	%>
	<br>
	<br>
	<br>
	<table cellspacing="1" cellpadding="1" border="1">
		<tr>
			<td><%=Account.investmentLabel%>=<%=acct.investment%></td>
			<td><%=Account.profitLabel%>=<label name="<%=Account.profitName%>"><%=acct.profit%></label></td>
			<td><%=Account.profitRateLabel%>=<label name="<%=Account.profitRateName%>"><%=acct.profitRate%></label></td>
			<td><%=Account.assetLabel%>=<label name="<%=Account.assetName%>"><%=acct.asset%></label></td>
			<td><%=Account.cashLabel%>=<%=acct.cash%></td>
			<td><%=Account.marketValueLabel%>=<%=acct.marketValue%></td>
			<td><%=Account.asset2Label%>=<label name="<%=Account.asset2Name%>"><%=acct.asset2%></label></td>
		</tr>
		<tr>
			<td id="investment4Deposit"><%=Account.investmentLabel%>=<%=acct.investment%></td>
			<td >利息=<input id="interest4Deposit" value="3.1" style="width: 40px;"></td>
			<td id="startDate4Depoist">StartDate=2010-01-28</td>
			<td id="profit4Deposit" >利润=</td>
			<td id="profit4DepositRate">利润率=</td>
			<td id="asset4Deposit">资产=</td>
			<td><input name="calc" type="button" value="Calc" onclick="calc4Deposit()"></td>
			<script type="text/javascript">
				function calc4Deposit(){
					var investment = document.getElementById('investment4Deposit').innerText.substr(3);
					var interest = document.getElementById('interest4Deposit').value;
					interest = interest / 100 ;
					var startDate = new Date("2010-01-28");
					var now = new Date();
					var term = (now.getFullYear() - startDate.getFullYear())
							+ (now.getMonth() - startDate.getMonth())/12
							+ (now.getDate() - startDate.getDate())/365
					var profitRate = Math.pow((1+interest), term) - 1;
					var asset = investment * ( profitRate + 1 );
					document.getElementById('profit4Deposit').innerText = '利润=' + (asset - investment);
					document.getElementById('profit4DepositRate').innerText = '利润率=' + profitRate * 100 + '%';
					document.getElementById('asset4Deposit').innerText = '资产=' + asset;
				}
			</script>
		</tr>
	</table>
	<%
		}
	%>
	<script type="text/javascript">
	    var elemNames = ['<%=Account.assetName%>','<%=Account.profitName%>'];
	    toFixedFloatByName(elemNames,'label');
	    var elemNames =['<%=Account.profitRateName%>'];
	    toFixedPercentageByName(elemNames,'label');
	</script>
</div>
<div>
	<p>
	<br>
	<br>
	<br><%=Stock.currentInvestmentLabel%>: 是当根据前持有数量，从后向前推，所得到的投资额，也就是最后若干手的购买成本。 <br>
	<br>
	</p>
	<p>此轮是计算从上次卖光之后的所有交易。 
	<br><%=Stock.thisProfitWithoutCurrentMarketValueLabel%>: 是从上次卖光之后的所有交易的盈亏，不计之前的盈亏。 <br><%=Stock.thisBaobenPriceLabel%>:
	是从上次卖光之后的所有交易的保本价格，不计之前的盈亏。 <br>
	<br>
	</p>
	<p><%=Stock.stockProfitWithoutCurrentMarketValueLabel%>=所有买入卖出的发生金额之和，所以对于仍然持有股份的股票，很可能为负值。 <br><%=Stock.stockBaobenPriceLabel%><%=Stock.stockProfitWithoutCurrentMarketValueLabel%><%=Stock.currentAmountLabel%>
	<br><%=Stock.stockProfitLabel%>=<%=Stock.stockProfitWithoutCurrentMarketValueLabel%><%=Stock.currentMarketValueLabel%>
	<br><%=Stock.stockProfitRateLabel%>=<%=Stock.stockProfitLabel%><%=Stock.stockInvestmentLabel%>
	</p>
</div>
</body>
</html>